package com.prd.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.prd.config.LoginInterceptor;
import com.prd.dto.OaDepartWorkHandoverDTO;
import com.prd.model.OaDepartWorkHandoverDO;
import com.prd.service.OaDepartWorkHandoverService;
import com.prd.util.CommonUtil;
import com.prd.util.JsonData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 工作交接记录表 前端控制器
 * </p>
 *
 * @author lizhaoyi
 * @since 2024-01-01
 */
@RestController
@RequestMapping("/api/oaDepartWorkHandover")
@Api(tags = "离职交接事项相关接口")
public class OaDepartWorkHandoverController {

    @Autowired
    private OaDepartWorkHandoverService oaDepartWorkHandoverService;

    @ApiOperation("添加工作交接事项")
    @PostMapping("add")
    public JsonData add(@RequestBody OaDepartWorkHandoverDTO oaDepartWorkHandoverDTO){

        OaDepartWorkHandoverDO oaDepartWorkHandoverDO = CommonUtil.dtoTransfer(oaDepartWorkHandoverDTO, OaDepartWorkHandoverDO.class);
        oaDepartWorkHandoverDO.setCreatedBy(LoginInterceptor.threadLocal.get().getName());
        oaDepartWorkHandoverDO.setCreatedTime(LocalDateTime.now());
        oaDepartWorkHandoverService.saveOrUpdate(oaDepartWorkHandoverDO);
        return JsonData.buildSuccess();
    }

    @ApiOperation("查询工作交接事项列表")
    @PostMapping("list")
    public JsonData list(@ApiParam("离职记录id") @RequestParam(value = "departId") String departId){

        return JsonData.buildSuccess(oaDepartWorkHandoverService.list(new LambdaQueryWrapper<OaDepartWorkHandoverDO>().eq(OaDepartWorkHandoverDO::getDepartId, departId)));
    }

    @ApiOperation("查询工作交接事项详情")
    @PostMapping("detail")
    public JsonData detail(@ApiParam("交接事项id") @RequestParam(value = "id") String id){

        return JsonData.buildSuccess(oaDepartWorkHandoverService.getById(id));
    }

}

